// 总卦排列
<template>
  <div class="page">
    <div class="content" v-if="config">
      <div class="item" v-for="base in config.values()" :key="base.id">
        <h2>{{ base.name }}</h2>
        <!-- 卦体 -->
        <div class="main" v-for="item in base.children.values()" :key="item.id">
          <div class="left">
            <div class="text border">{{ base.appearance }}</div>
            <div class="text">{{ item.appearance }}</div>
          </div>
          <div class="center">=</div>
          <div class="right">
            <input
              type="text"
              placeholder="卦名"
              @blur="(e) => validate(e, base, item)"
            />
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import Config from "../data/config";
const config = ref(Config);
const validate = (e, outer, inner) => {
  e.preventDefault();
  const value = e.target.value;
  if (!value) {
    return false;
  }
  const result = inner.result;
  if (result && Array.isArray(result)) {
    if (!result.includes(value.trim())) {
      window.alert(
        `正确答案应该是: ${outer.appearance} + ${inner.appearance} = ${result.join("/ ")}`
      );
      return false;
    } else {
      console.info(`正确: ${outer.appearance} + ${inner.appearance} = ${result[0]}`);
    }
  }
};
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped lang="scss">
.page {
  width: 100%;
  padding: 20px;
  .button {
    padding: 5px 10px;
  }
  .content {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    align-items: center;
    .item {
      margin-bottom: 20px;
      text-align: center;
    }
    .main {
      font-size: 20px;
      display: flex;
      justify-content: space-around;
      align-items: center;
      margin-top: 20px;
      border: 1px dashed black;
      padding: 15px;

      .left {
        .text {
          font-weight: 500;
          padding: 10px;
        }
        .border {
          border-bottom: 2px solid black;
        }
      }
      .center {
        margin: 10px;
      }
      .right {
        input {
          border: 1.5px solid aquamarine;
          outline: none;
          padding: 10px;
          border-radius: 5px;
          color: red;
          font-size: 20px;
          width: 80px;
        }
      }
    }
  }
}
</style>
